<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>


<script>

    alert(findPalindromeStr('abc123321xabcde2edcbaqq'));

    //alert(findPalindromeStr('abc1cba'));

    function findPalindromeStr(str){

        let strArr = str.split('');
        let len = strArr.length;
        let maxLeft = 0;
        let maxRight = 0;
        let maxPalindromeStrLen = 0;
        for(let i = 0; i< len; i ++){ // 回文字符串的结果可能是 偶数  abccba
            if(strArr[i] == strArr[i + 1]){
                let left = i;
                let right = i + 1;
                let tmpMaxPalindromeStrLen = 0;
                while((left >= 0) && (right < len) && (strArr[left] == strArr[right])){
                    left --;
                    right ++;
                    tmpMaxPalindromeStrLen = tmpMaxPalindromeStrLen + 2;
                }
                if(tmpMaxPalindromeStrLen > maxPalindromeStrLen){
                    maxPalindromeStrLen = tmpMaxPalindromeStrLen;
                    maxLeft = left + 1;
                    maxRight = right - 1;
                }
            }

            if(strArr[i] == strArr[i + 2]){ // 回文字符串的结果可能是 奇数  abc1cba
                let left = i;
                let right = i + 2;
                let tmpMaxPalindromeStrLen = 1;
                while((left >= 0) && (right < len) && (strArr[left] == strArr[right])){
                    left --;
                    right ++;
                    tmpMaxPalindromeStrLen = tmpMaxPalindromeStrLen + 2;
                }
                if(tmpMaxPalindromeStrLen > maxPalindromeStrLen){
                    maxPalindromeStrLen = tmpMaxPalindromeStrLen;
                    maxLeft = left + 1;
                    maxRight = right - 1;
                }
            }
        }
        return str.substring(maxLeft, maxRight + 1);
    }
</script>

</body>
</html>